﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace PeisongWeb.admin
{
    public partial class partnerList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (hasPermission("AE", 1))
                {
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            DataSet ds = logic.partner.select(where.ToString(), "pid", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int pid = Convert.ToInt32(e.CommandArgument);
                DAL.PartnerEntity partner = logic.partner.getById(pid);
                if (!string.IsNullOrEmpty(partner.ImgName))
                {
                    try
                    {
                        Library.FileLib.Del(Library.Resource.UploadPath + Library.Resource.FileOriginal + "/" + partner.ImgName);
                    }
                    catch(Exception ex)
                    {
                        Library.Script.ClientMsg(ex.Message);
                    }
                }
                logic.partner.delete(pid);
                rptBind();
                string infor = "删除成功！";
                Library.Script.ClientMsg(infor);
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
